package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.entity.enums.activity.huashigang.eHuaShiGangEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = GameProtocol.S_HUA_SHI_GANG_SHENXING_FROM_CROSS, desc = "神行千里 跨服返回")
public class ShenXingFromCossCmd extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        HuaShiGangProto.ShenXingQianLiCrossRespMsg crossBackMsg = HuaShiGangProto.ShenXingQianLiCrossRespMsg.parseFrom(packet.getBytes());

        HuaShiGangProto.ShenXingQianLiRespMsg.Builder clientMsg = HuaShiGangProto.ShenXingQianLiRespMsg.newBuilder();
        clientMsg.setRet(crossBackMsg.getRet());

        Property totalReward = new Property();
        for (HuaShiGangProto.OpenTreasureFromCross openTreasureFromCross : crossBackMsg.getTreasureRespList()) {
            Property reward = PropertyHelper.parseStringToProperty(openTreasureFromCross.getReward());
            totalReward.addProperty(reward);

            clientMsg.addTreasureResp(HuaShiGangProto.OpenTreasureRespMsg.newBuilder().setRet(0).setReward(openTreasureFromCross.getReward()).setGood(openTreasureFromCross.getGood()));
        }

        if (!totalReward.isNothing()) {
            player.getModule(CurrencyModule.class).addCurrency(totalReward, eLogMoneyType.HuaShiGang, eLogMoneyType.HuaShiGangOpenTreasure);
        }

        player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_SHEN_XING, clientMsg);

        player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_USER_DATA_NOTIFY, crossBackMsg.getUserData().toBuilder());

    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
